class Restaurant {
  int? id; // 可为空，因为新建时还没有ID
  final String name;
  final String? contact; // 可为空的字段
  final String? phone;
  final String? address;

  Restaurant({
    this.id,
    required this.name,
    this.contact,
    this.phone,
    this.address,
  });

  // 将模型转换为Map，用于存入数据库
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'name': name,
      'contact': contact,
      'phone': phone,
      'address': address,
    };
  }

  // 从数据库的Map数据构造一个Restaurant模型
  factory Restaurant.fromMap(Map<String, dynamic> map) {
    return Restaurant(
      id: map['id'],
      name: map['name'],
      contact: map['contact'],
      phone: map['phone'],
      address: map['address'],
    );
  }

  // 创建一个副本，可用于编辑
  Restaurant copyWith({
    int? id,
    String? name,
    String? contact,
    String? phone,
    String? address,
  }) {
    return Restaurant(
      id: id ?? this.id,
      name: name ?? this.name,
      contact: contact ?? this.contact,
      phone: phone ?? this.phone,
      address: address ?? this.address,
    );
  }
}